﻿package zf.media.audio.spectrum
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.filters.BlurFilter;
	import flash.geom.ColorTransform;
	import flash.geom.Point;
	
	import zf.media.audio.SoundSpectrumMode;

	/**
	 * 圆形声谱图形 
	 * @author mike.zhang
	 * 
	 */
	public class CircleSpectrum extends SoundSpectrum
	{
		private var lineSprite1:Sprite;
		private var lineSprite2:Sprite;
		//private var bgData:BitmapData;
		
		private var maxr:Number;
		//private var lp:Point;
		//private var rp:Point;
		private var ccp:Point;
		private var zjd:Number;
		private var randomCt2:ColorTransform;
		
		private var c1:Number;
		private var c2:Number;
		private var s1:Number;
		private var s2:Number;
		
		private var bd1:BitmapData;
		private var bd2:BitmapData;
		/**
		 * 创建一个圆形声谱图形 
		 * @param w 宽度
		 * @param h 高度
		 * 
		 */
		public function CircleSpectrum(w:Number,h:Number):void
		{
			super(w,h);
			type=SoundSpectrumMode.CS;
			randomCt2=getCt();
			abs=true;
			machining=true;
			ff=2;
			maxr=ww>hh?hh:ww;
			maxr*=0.25;
			zjd=0;
			//lp=new Point(ww/2-maxr,hh/2);
			//rp=new Point(ww/2+maxr,hh/2);
			ccp=new Point(ww/2,hh/2);
			lineSprite1=new Sprite;
			lineSprite2=new Sprite;
			//bgData=new BitmapData(ww,hh,false,0x000000);
			//addChild(new Bitmap(bgData));
		}
		/**
		 * @private 
		 * 
		 */
		override protected function draw():void
		{
			super.draw();
			lineSprite1.graphics.clear();
			lineSprite2.graphics.clear();
			//lineSprite.graphics.lineStyle(1.5,0xFFFFFF);
			lineSprite1.graphics.lineStyle (1.5, randomCt.color);
			lineSprite2.graphics.lineStyle (1.5, randomCt2.color);
			c1=Math.cos(zjd+Math.PI);
			s1=Math.sin(zjd+Math.PI);
			c2=Math.cos(zjd);
			s2=Math.sin(zjd);
			lineSprite1.graphics.drawCircle(ccp.x+c1*maxr,ccp.y+s1*maxr,maxr*Math.abs(byArr[0]));
			lineSprite2.graphics.drawCircle(ccp.x+c2*maxr,ccp.y+s2*maxr,maxr*Math.abs(byArr[1]));
			zjd+=0.01;
			
			bd1=new BitmapData(ww,hh,true,0x00FFFFFF);
			bd2=new BitmapData(ww,hh,true,0x00FFFFFF);
			bd1.draw (lineSprite1,null,null,"add");
			bd2.draw (lineSprite2,null,null,"add");
			bd1.scroll(c1,s1);
			bd2.scroll(c2,s2);
			_bg.bitmapData.draw (bd1,null,null,_blendMode);
			_bg.bitmapData.draw (bd2,null,null,_blendMode);
			_bg.bitmapData.applyFilter (_bg.bitmapData,_bg.bitmapData.rect,new Point(),new BlurFilter(2,2,1));
			_bg.bitmapData.colorTransform (_bg.bitmapData.rect,new ColorTransform(1, 1, 1, 1, -5, -10, -10));
			//_bg.bitmapData.scroll(0,1);
		}
		override public function defaultConfig():void
		{
			abs=true;
			machining=true;
		}
	}
}